from selenium import webdriver  #用于操作浏览器
from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器
from selenium.webdriver.chrome.service import Service #用于管理驱动
from selenium.webdriver.common.by import By
import time
import pyautogui
from selenium.webdriver.common.alert import Alert

#设置浏览器/启动浏览器
def she():
    #创建设置浏览器对象
    hycx = Options()
    #禁用浏览器沙盒模式
    hycx.add_argument('--no-sandbox')
    #保持浏览器的打开状态
    hycx.add_experimental_option('detach',True)
    #创建并启动浏览器
    a1 = webdriver.Chrome(service=Service('../chromedriver.exe'), options=hycx)
    return a1
a1 = she()

a1.get('http://8.147.105.44:3001/login?redirect=%2Findex')

################ 点击触发警告框的元素#######################

########################################################

time.sleep(2)
a1.maximize_window()
#定位账号元素
a2=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/form/div[1]/div/div[1]/input')
#输入账号
a2.send_keys('fujipeng')
#定位密码元素
time.sleep(1)
a3=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/form/div[2]/div/div[1]/input')
#输入密码
a3.send_keys('123456')
#定位登录按钮元素
time.sleep(1)
a5 = a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/form/div[3]/div/label/span[1]/span').click()
time.sleep(2)
a4=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/form/div[4]/div/button/span/span').click()
time.sleep(5)
#点击登录

test_ty = [
    "CK20250604-000002","拼多多","JY20250604-000002","TY20250604-000002",
    "顺丰速递","QY20250604-000002","50","小米手机" ,"台","5000"
]
#点击进入退运订单
ty1=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[1]/div[2]/div[1]/div/ul/div[6]/li/div/i').click()
time.sleep(1)
#点击退运进入列表
ty2=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[1]/div[2]/div[1]/div/ul/div[6]/li/ul/div[2]/a/li').click()
time.sleep(1)
#点击新增按钮
ty3=a1.find_element(By.XPATH,'/html/body/div/div[1]/div[2]/section/div/div[1]/button').click()
time.sleep(2)
#输入原出口单号
ty4=a1.find_element(By.XPATH,'/html/body/div/div[1]/div[2]/section/div/form/div[1]/div[2]/div/div[2]/div/div[1]/input')
ty4.send_keys(test_ty[0])
#电商平台名称
ty5=a1.find_element(By.XPATH,'/html/body/div/div[1]/div[2]/section/div/form/div[1]/div[2]/div/div[3]/div/div[1]/input')
ty5.send_keys(test_ty[1])
#平台交易单号
ty6=a1.find_element(By.XPATH,'/html/body/div/div[1]/div[2]/section/div/form/div[1]/div[2]/div/div[4]/div/div/input')
ty6.send_keys(test_ty[2])
#平台退运单号
ty7=a1.find_element(By.XPATH,'/html/body/div/div[1]/div[2]/section/div/form/div[1]/div[2]/div/div[5]/div/div/input')
ty7.send_keys(test_ty[3])
#物流企业名称
ty8 =a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[2]/div/div[7]/div/div[1]/input')
ty8.send_keys(test_ty[4])
#物流企业代码
ty9 =a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[2]/div/div[8]/div/div[1]/input')
ty9.send_keys(test_ty[5])
#包裹重量
ty10 =a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[2]/div/div[9]/div/div[1]/input')
ty10.send_keys(test_ty[6])
#备注




#商品明细
#添加行
mx1 =a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[2]/div[2]/button').click()
time.sleep(2)
#输入商品名称
mx2 =a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[2]/div[2]/div/div[3]/table/tbody/tr/td[2]/div/div/input')
mx2.send_keys(test_ty[7])
#输入申报计量单位
mx2 =a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[2]/div[2]/div/div[3]/table/tbody/tr/td[3]/div/div/input')
mx2.send_keys(test_ty[8])
#输入申报数量
mx3 =a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[2]/div[2]/div/div[3]/table/tbody/tr/td[4]/div/div/input')
mx3.clear()
mx3.send_keys(test_ty[9])
#点击保存
mx4 =a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[2]/div[2]/div/div[4]/div[2]/table/tbody/tr/td[6]/div/button[1]').click()



#单证资料
dz1=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[3]/div[2]/div[1]/div[1]/div/div/div/div[1]/span/span/i').click()
time.sleep(2)
dz2=a1.find_element(By.XPATH,'/html/body/div[2]/div[1]/div[1]/ul/li[2]').click()
dz4=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[3]/div[2]/div[1]/div[2]/div/div/button').click()
time.sleep(2)
pyautogui.typewrite("C:\\Users\\Lenovo\\Downloads\\test.docx")
pyautogui.press("enter")
pyautogui.press("enter")
time.sleep(5)
a1.execute_script("window.scrollTo(0, document.body.scrollHeight);")



#提交/
tj1=a1.find_element(By.XPATH,'html/body/div[1]/div[1]/div[2]/section/div/div[1]/button[3]').click()
